;
(function() {
	var industryData = new Vue({
		el: '#industry',
		data() {
			return {
				industryDate: '',
				projectList: [],
				projectId: [],
			}
		},
		methods: {
			selectD() {
				industry.data()
			},
			getProjectData() {
				hlhttp.get({
					url: 'user/projects',
					success: (data) => {
						data.unshift({
							projectName: '全部',
							projectId: '#'
						})
						this.projectList = hlArrayUtil.replaceData(data, [{
							key: 'projectName',
							rKey: 'name'
						}, {
							key: 'projectId',
							rKey: 'code'
						}]);
					}
				})
			},
			selectProjectId() {
				industry.data()
			}
		},
		mounted() {
			this.getProjectData()
		}
	})

	var chart = null;
	var industry = {
		init: function() {
			this.date()
			this.data()
			this.selectDate()
		},
		//统计行业出租面积分布
		data: function() {
			var data = {
				date: industryData.industryDate,
				project_id: industryData.projectId.length ? industryData.projectId[0] : '#'
			}
			var self = this;

			hlhttp.get({
				url: 'report/acreage_by_industry',
				data: data,
				success: function(data) {
					if (!data.industryList.length) {
						// $('.nodata').show()
						$('.industry-container').html('暂无数据')
						return
					} else {
						$('.industry-container').html('')
						// $('.nodata').hide()
					}
					var arr = [];

					hlhttp.get({
						url: 'configure/industry/dict',
						success: function(res) {
							res.map(function(item) {
								data.industryList.map(function(item1) {
									if (item.dictCode == item1
										.industryType) {
										arr.push([item.dictName,
											Number(item1
												.acreage)
										])
									}
								})
							})

							self.charts(arr, data.companyCount)
						}
					})

				}
			})
		},
		//今天日期
		date: function() {
			function GetDateStr(AddDayCount) {
				var dd = new Date();
				dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
				var y = dd.getFullYear();
				var m = dd.getMonth() + 1; //获取当前月份的日期
				var d = dd.getDate();
				return y + "-" + tzero(m) + "-" + tzero(d);
			}
			// $('.industry-date').attr('value', GetDateStr(-1))
			industryData.industryDate = GetDateStr(-1)

		},
		//根据时间选择柱形图
		selectDate: function() {
			var self = this;
			$('.dt-dateControl').unbind().on('click', '.day-item', function(event) {
				if (window.location.hash.indexOf('#/industry') >= 0) {
					setTimeout(function() {
						self.data()
					}, 200);
				}

			});
		},
		//charts
		charts: function(data, count) {
			console.log(data)
			$(function() {
				$('.industry-container').highcharts({
					chart: {
						plotBackgroundColor: null,
						plotBorderWidth: null,
						plotShadow: false,
						spacing: [0, 0, 0, 0]
					},
					colors: ['#A88EDA', '#FA83AB', '#F8D86A', '#7FC684', '#69C8FF',
						'#B6F8DA'
					],
					title: {
						floating: true,
						useHTML: true,
						style: {
							color: '#333',
							fontWeight: '100',
							top: '50%',
							left: '50%',
							transform: 'translate(0,-35%)',
							textAlign: 'center',
							zIndex: '0'
						},
						text: '总企业数<p style="font-size:48px;color:#565E99;">' + count +
							'</p>'
					},
					tooltip: {
						shared: true,
						enabled: true,
						useHTML: true,
						padding: 0,
						backgroundColor: 'rgba(247,247,255,0)',
						valueDecimals: 2,
						headerFormat: '<span class="font-size:14px">{point.key}</span>',
						pointFormat: '面积: {point.y:.1f}m²',
						borderWidth: 0,
						style: {
							fontSize: '14px'
						}
					},

					plotOptions: {
						pie: {
							enabled: true,
							cursor: 'pointer',
							borderWidth: 2,
							
							dataLabels: {
								shared: true,
								useHTML: true,
								valueDecimals: 2,
								enabled: false,
								format: '<b>{point.name}</b>: {point.percentage:.2f} %',
								style: {
									color: '#666',
									fontFamily: 'Microsoft Yahei',
									fontSize: '14px'
								}
							},
							showInLegend: true
						},
					},

					series: [{
						type: 'pie',
						innerSize: '60%',
						name: ' ',
						data: data
					}]
				}, function(c) {
					// 环形图圆心
					var centerY = c.series[0].center[1],
						titleHeight = parseInt(c.title.styles.fontSize);
					c.setTitle({
						y: centerY + titleHeight / 2
					});
					chart = c;
				});
			});
		}
	}
	industry.init()

	function tzero(n) {
		return n < 10 ? '0' + n : '' + n
	}
	//MI制造业、、、、、、、、、、、、、、、、
	function industryType(state) {
		var result;
		switch (state) {
			case 'MI':
				result = '制造业'
				break;
			case 'JZ':
				result = '能源矿业'
				break;
			case 'PF':
				result = '建筑/房地产'
				break;
			case 'TR':
				result = '环保/公共设施'
				break;
			case 'ZS':
				result = '科研/技术服务'
				break;
			case 'IF':
				result = '农业'
				break;
			case 'JR':
				result = '医药/医疗/保健'
				break;
			case 'HS':
				result = '贸易/运输/物流'
				break;
			case 'ZL':
				result = '金融/投资'
				break;
			case 'SC':
				result = '零售/消费品'
				break;
			case 'JP':
				result = '教育/培训'
				break;
			case 'ED':
				result = '文化/体育/娱乐'
				break;
			case 'WS':
				result = 'IT/通讯/网络'
				break;
			case 'CU':
				result = '专业及商务服务'
				break;
			case 'PS':
				result = '政府/社会组织'
				break;
			case 'ET':
				result = '其他'
				break;
			default:
				result = ''
		}
		return result;
	}
}())
